package com.zbkj.front.service.impl;

import com.google.common.collect.Lists;
import com.zbkj.common.enums.ProductTypeEnum;
import com.zbkj.common.model.product.Product;
import com.zbkj.common.response.product.ClientProductResponse;
import com.zbkj.common.vo.product.ProductQueryVo;
import com.zbkj.front.service.ProductHandleService;
import com.zbkj.service.service.product.ProductService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Auther:
 * @Date: 2024/9/14 11:20
 * @Description:
 */
@Service
public class ProductHandleServiceImpl implements ProductHandleService {

    @Autowired
    private ProductService productService;

    @Override
    public List<ClientProductResponse> list() {
        ProductQueryVo queryVo = new ProductQueryVo();
        queryVo.setProductStatus(0);
        List<Product> productList = productService.getProductList(queryVo);
        List<ClientProductResponse> responseList = Lists.newArrayList();
        for(Product product : productList) {
            ClientProductResponse response = new ClientProductResponse();
            BeanUtils.copyProperties(product,response);
            responseList.add(response);
        }
        return responseList;
    }

    @Override
    public List<ClientProductResponse> getBuyProductList(Integer queryType) {
        ProductQueryVo queryVo = new ProductQueryVo();
        queryVo.setProductStatus(0);
        if(queryType == 1) {
            queryVo.setProductTypeList(ProductTypeEnum.getFlowDataTypeList());
        } else {
            queryVo.setProductTypeList(ProductTypeEnum.getReportDataTypeList());
        }
        List<Product> productList = productService.getProductList(queryVo);
        List<ClientProductResponse> responseList = Lists.newArrayList();
        for(Product product : productList) {
            ClientProductResponse response = new ClientProductResponse();
            BeanUtils.copyProperties(product,response);
            responseList.add(response);
        }
        return responseList;
    }
}
